package vivek.project.pocketmoney.common.logger
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import mx.core.mx_internal;
	import mx.logging.targets.LineFormattedTarget;
	
	import vivek.project.pocketmoney.admin.model.AdminDataCache;

	use namespace mx_internal;

	public class FileTarget extends LineFormattedTarget
	{
		private var  file:File = File.applicationStorageDirectory.resolvePath("logs/pm.log");
		private var fileStream:FileStream=new FileStream();
		public function FileTarget()
		{
			super();
			
			fileStream.openAsync(file, FileMode.APPEND);
			
			includeDate=true;
			includeTime=true;
			//includeCategory=true;
			includeLevel=true;
		}
		override mx_internal function internalLog(message:String):void
		{
			trace(message);
			AdminDataCache.logs.addItemAt(message, 0);
			fileStream.writeUTF(message);
		}
	}
}